<!DOCTYPE html>
<html xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
</head>
<form class="layui-form myData" action="save" method="post" enctype="multipart/form-data" lay-filter="stuform" id="save" style="display: none" >
    <input type="hidden" name="id"  />
    <fieldset class="layui-elem-field">
        <legend>任务编排信息</legend>
        <div class="layui-field-box">
            <div class="layui-form-item">
                <label class="layui-form-label">任务所属团队：</label>
                <div class="layui-input-block">
                    <select v-model="temp.teamId" id="teamList" lay-verify="required" lay-filter="xmFilter" class="teamList" lay-search="" name="tId">
                        <option value="">直接选择或搜索选择</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item" >
                <label class="layui-form-label">文件名模板：</label>
                <div class="layui-input-block">
                    <input v-model="temp.fileNameTemp" type="text" name="fileNameTemplate" class="layui-input" id="fileNamePlate"/><button type="button" class="layui-btn" onclick="addTemplate()">添加模板</button>
                </div>
            </div>

            <div class="layui-form">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">日期范围</label>
                        <div class="layui-inline" id="test6">
                            <div class="layui-input-inline">
                                <input v-model="temp.startTime" type="text" autocomplete="off" id="startTime" name="startTime" class="layui-input" placeholder="开始日期">
                            </div>
                            <div class="layui-form-mid">-</div>
                            <div class="layui-input-inline">
                                <input v-model="temp.endTime" type="text" autocomplete="off" id="endTime" name="endTime" class="layui-input" placeholder="结束日期">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </fieldset>

    <fieldset class="layui-elem-field" >
        <legend>定时任务编排信息</legend>

        <div class="layui-field-box" >
            <div v-for="num in ParamsNum" :key="num">
                <div class="layui-form-item">
                    <label class="layui-form-label">邮件主题：</label>
                    <div class="layui-input-block">
                        <input type="text" name="subject" lay-verify="required"  class="layui-input" v-model="temp.params[num].subject"/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">邮件内容：</label>
                    <div class="layui-input-block">
                        <textarea v-model="temp.params[num].content" name="content" placeholder="默认内容:共计{headCount}人,实交{practical}人。{没有交作业的人:noSubmitNames}" class="layui-textarea" ></textarea>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">接收方：</label>
                    <div class="layui-input-block">
                        <select v-model="temp.params[num].receive" id="emailList" lay-filter="xmFilter"  lay-search="" name="receive">
                            <option value="">直接选择或搜索选择</option>
                        </select>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">发送时间：</label>
                    <div class="layui-input-block">
                        <input v-model="temp.params[num].sendTime" type="text" class="layui-input" id="test1" name="sendTime" placeholder="yyyy-MM-dd HH:mm:ss">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">邮件方式</label>
                    <div class="layui-input-block" >
                        <select name="way" v-model="temp.params[num].way" id="emailNoticeList" >
                            <option value="0" >通知</option>
                            <option value="1">交作业</option>
                        </select>
                    </div>
                </div>
                <hr class="layui-border-red">
            </div>

            <button type="button" class="layui-btn" @click="handleAddParams">增加定时任务</button>
            <div class="layui-form-item">
                <blockquote class="layui-elem-quote">通知:用于发送任务状态(供负责人查看作业记录)。
                    <br>交作业:最后提交作业(携带作业)</blockquote>
            </div>
        </div>
    </fieldset>
</form>
<form class="layui-form myData" action="save" method="post" lay-filter="stuform" id="temp" style="display: none" >
    <div class="layui-form-item" >
        <label class="layui-form-label">模板样例:</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" value="{name}{studentNumber}" readonly/>
        </div>
    </div>
    <div class="layui-form-item" >
        <label class="layui-form-label">模板解析后:</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" value="张三22B120" readonly/>
        </div>
    </div>
    <div class="layui-form-item" >
        <label class="layui-form-label">模板样例:</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" value="{name}{studentNumber} Java作业" readonly/>
        </div>
    </div>
    <div class="layui-form-item" >
        <label class="layui-form-label">模板解析后:</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" value="张三22B120 Java作业" readonly/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">可选择的模板变量</label>
        <div class="layui-input-block">
            <select name="city" lay-verify="required">
                <option value=""></option>
                <option value="0">昵称: {name}</option>
                <option value="1">学号: {studentNumber}</option>
                <option value="2">邮箱: {email}</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item" >
        <label class="layui-form-label">输入相应模板(模板中不能出现+ / \)：</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" id="inputFileNamePlate" />
        </div>
    </div>
</form>
<body>
<div class="layuimini-container" >
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">任务名称</label>
                            <div class="layui-input-inline">
                                <input type="text" name="taskName" autocomplete="off" class="layui-input" id="taskName">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="button" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 添加 </button>
                <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete"> 删除 </button>

            </div>

        </script>
        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>



    </div>
</div>
<script type="text/html" id="status">
    {{#  if(d.timeState === true ){ }}
    <button class="layui-btn layui-btn-xs layui-btn-normal">进行中</button>
    {{#  } }}
    {{#  if(d.timeState === false ){ }}
    <button class="layui-btn layui-btn-xs layui-btn-danger">已结束</button>
    {{#  } }}
</script>

<script src="../../lib/layui-v2.7.3/layui/layui.js" charset="utf-8"></script>
<script src="../../api/urlConfig.js"></script>
<script src="../../lib/jquery-3.4.1/jquery-3.4.1.min.js"></script>
<script src="../../js/base64.min.js"></script>
<script src="../../js/vue.js"></script>

<script>
    function initTeam(){
        $.ajax({
            url: ipURL + '/caption/team/list',
            type: 'GET',
            dataType: 'json',
            beforeSend: function (request) {
                request.setRequestHeader("token", localStorage.token);
            },
            success: function (data) {
                $.each(data.data.data, function (index, value) {
                    $('.teamList').append(new Option(value.name,value.id));// 下拉菜单里添加元素
                });
                layui.form.render("select");//重新渲染 固定写法

            },
        });
    }
    function initEmailTable(){
        $.ajax({
            url: ipURL + '/caption/email-table/list',
            type: 'GET',
            dataType: 'json',
            beforeSend: function (request) {
                request.setRequestHeader("token", localStorage.token);
            },
            success: function (data) {

                $.each(data.data.data, function (index, value) {
                    $('#emailList').append(new Option(value.description,value.email));// 下拉菜单里添加元素

                });
                layui.form.render("select");//重新渲染 固定写法

            },
        });
    }

    $(function () {
        initEmailTable()
        initTeam()
    })
    var vm = new Vue({
        el: "#save",
        data() {
            return {
                temp: {
                    teamId:null,
                    fileNameTemp:'',
                    startTime:'',
                    endTime:'',
                    params: [{subject:'',content:'',receive:'',sendTime:'',way:''}]
                },
                ParamsNum: 0
            }
        },

        methods: {

            handleAddParams() {

                this.temp.params.push({subject:'',content:'',receive:'',sendTime:'',way:''})
                this.ParamsNum++
                initEmailTable()
                layui.use(['laydate'], function () {
                    var laydate = layui.laydate;

                    //执行一个laydate实例
                    laydate.render({
                        elem: '#test1' //指定元素
                        ,type: 'datetime'
                        ,min: 0
                    });
                })
            },
            handleDeleteParams(num) {
                this.ParamsNum--
                this.temp.params.splice(num,1)
            }
        }


    });






    layui.use(['form', 'table','upload','laydate'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#test1' //指定元素
            ,type: 'datetime'
            ,min: 0
        });


        table.render({
            elem: '#currentTableId',
            // url: '../api/table.json',	
			// url:ipURL+"/caption/task/page",
            headers:{token:localStorage.token},
			parseData: function(res){ //res 即为原始返回的数据
			    return {
			      "code": res.code, //解析接口状态
			      "msg": res.message, //解析提示文本
			      "count": res.count, //解析数据长度
			      "data": res.data.data,//解析数据列表
				  
			    };	
				
			},
			
			response: {
			            statusCode: 0//规定成功的状态码，默认：0
			        },
			text:{none: '无数据'},
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {type: "checkbox", width: 50},
                {field: 'id', width: 80, title: 'ID', sort: true,hide:true},
                {field: 'name', title: '名称',width:150},
                {field: 'teamName',  title: '所属团队',width:150},
                {field: 'timeState', title: '状态' ,templet: '#status',width:100},
                {field: 'finishState',  title: '提交状态',width:100},
                {field: 'endTime',  title: '结束时间',width:200},
                {title: '操作', minWidth: 200,  align: "center",
                    templet: function(d){

                        var operation = '';
                        if (d.url!=''){
                            operation += `<a class='layui-btn layui-btn-warm layui-btn-xs ' lay-event="showDescription" >查看作业</a>`;
                        }
                        operation += `<a class='layui-btn layui-btn-normal layui-btn-xs data-count-edit' lay-event="show" >查看记录</a>`;
                        operation+=" "
                        operation += `<a class='layui-btn layui-btn-normal layui-btn-xs data-count-edit' lay-event="edit" >编辑</a>`;
                        operation+=" "
                        operation += `<a class='layui-btn layui-btn-danger layui-btn-xs data-count-edit' lay-event="delete" >删除</a>`;
                        operation+=" "



                        return operation
                    }}
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true,
            skin: 'line'
        });






        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
			
			var taskName = $('input[name="taskName"]').val()
            //执行搜索重载
            table.reload('currentTableId', {
				
                page: {
                    curr: 1
                }
                , where: {
                    name:taskName,
                }
            });

            return false;
        });




        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听添加操作
                layer.open({
                    type: 1,
                    title: '发布任务',
                    area: ['850px', '500px'],
                    content: $('#save'),
                    btn: ['提交', '退出'],
                    end:function(){
                        $('#save').css('display','none')
                    },
                    yes:function(){
                        console.log(vm.temp)
                    },

                    success:function(layero,index){

                    }
                })

            }  if (obj.event === 'delete') {  // 监听删除操作


				
            }
        });



        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {

                layer.open({
                    type: 1,
                    title: '修改',
                    area: ['850px', '500px'],

                    content: $('#save'),
                    btn: ['提交', '退出'],
                    end:function(){
                        $('#save').css('display','none')
                    },
                    yes:function(){
                    },

                    success:function(layero,index){


                    }
                })
                return false;
            } else if (obj.event === 'delete') {

            }else if (obj.event === 'show') {

                var index = layer.open({
                    title: data.name + "任务收集信息",
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: 'task-record.html',
                    success: function (layero, index) {
                        var iframe = window['layui-layer-iframe' + index];

                        iframe.child(data);
                    }
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            }
        });

    });

    layui.use('laydate', function() {
        var laydate = layui.laydate;
        // 开始时间日期
        laydate.render({
            elem: '#test6'
            ,type: 'datetime'
            ,range: ['#startTime', '#endTime']
        });


    });

    function addTemplate() {
        layer.open({
            type: 1,
            title: '模板',
            area: ['550px', '500px'],

            content: $('#temp'),
            btn: ['校验模板','提交模板', '退出'],
            end:function(){
                $('#temp').css('display','none')
            },
            yes:function(){
                $.ajax({
                    url: ipURL + '/parseTemp',
                    method: 'post',
                    data: {
                        template:$('#inputFileNamePlate').val()
                    },
                    beforeSend: function (request) {
                        request.setRequestHeader("token", localStorage.token);
                    },
                    success: function (res) {
                        layer.msg(res.message);
                        if (res.state){
                            layer.close(index);
                        }
                    },
                    error: function (data) {
                        layer.msg(data.message);
                    }
                });
            },

            btn2:function(layero,index){
                $('#fileNamePlate').val($('#inputFileNamePlate').val())
            }
        })
    }

</script>

</body>
<style>
    .typelist {
        width: 100%;
        /*background-color: white;*/
        height: 38px;
        line-height: 1.3;
        line-height: 38px;
        border-width: 1px;
        border-style: solid;
        background-color: #fff;
        border-radius: 2px;
    }
</style>
<style type="text/css">
    .myData .layui-form-item{
        margin: 20px 100px 10px 45px;
    }
    .myData .layui-form-label{
        width: 80px;
    }
</style>



</html>